#include <iostream>
#include <vector>
#include <Vector.hpp>
using namespace std;

class Solution
{
public:
    vector<vector<int>> permute(vector<int> &nums)
    {
        vector<vector<int>> res;
        vector<int> path;
        vector<bool> used(nums.size(), false);
        dfs(path, used, res, nums);
        return res;
    }

    void dfs(vector<int> &path, vector<bool> &used, vector<vector<int>> &res, vector<int> &nums)
    {
        if (path.size() == nums.size())
        {
            res.push_back(path);
            return;
        }
        for (int i = 0; i < used.size(); i++)
        {
            if (used[i] == false)
            {
                path.push_back(nums[i]);
                used[i] = true;
                dfs(path, used, res, nums);
                path.pop_back();
                used[i] = false;
            }
        }
    }
};
int main()
{
    cout << "Code46" << endl;
    Solution s;
    vector<int> nums = {1, 2, 3};
    vector<vector<int>> res = s.permute(nums);
    Print2DVector(res);
    return 0;
}